#! /usr/bin/env python2.5

from p60 import comb
from p60 import perm
all=set(range(1,10))

def isWanted(n):
    '''
    if the four digit number n is we wanted
    '''
    gg=n[0]*1000+n[1]*100+n[2]*10+n[3]
    remain = list(all - set(n))
    for i in comb(remain,1):
        r = list(set(remain)-set(i))
        for j in perm(r):
            k1=i[0]
            k2=j[0]*1000+j[1]*100+j[2]*10+j[3]
            if k1*k2==gg:
                return True
    for m in comb(remain,2):
        r = list(set(remain)-set(m))
        for i in perm(m):
            for j in perm(r):
                k1=i[0]*10+i[1]
                k2=j[0]*100+j[1]*10+j[2]
                if k1*k2==gg:
                    return True
    return False
print sum([i[0]*1000+i[1]*100+i[2]*10+i[3] for i in perm(list(all),4) if isWanted(i)])
